class PipTools < Formula
  include Language::Python::Virtualenv

  desc "Locking and sync for Pip requirements files"
  homepage "https://pip-tools.readthedocs.io"
  url "https://files.pythonhosted.org/packages/c4/79/d149fb40bc425ad9defcb8ff73c65088bbc36a84b1825e035397d1c40624/pip_tools-7.5.2.tar.gz"
  sha256 "2d64d72da6a044da1110257d333960563d7a4743637e8617dd2610ae7b82d60f"
  license "BSD-3-Clause"
  head "https://github.com/jazzband/pip-tools.git", branch: "main"

  bottle do
    sha256 cellar: :any_skip_relocation, arm64_tahoe:   "bf47e62934bd709f38814d509ec47f5cf8f2ac1503eb259f6bf9ab8195e8130a"
    sha256 cellar: :any_skip_relocation, arm64_sequoia: "bf47e62934bd709f38814d509ec47f5cf8f2ac1503eb259f6bf9ab8195e8130a"
    sha256 cellar: :any_skip_relocation, arm64_sonoma:  "bf47e62934bd709f38814d509ec47f5cf8f2ac1503eb259f6bf9ab8195e8130a"
    sha256 cellar: :any_skip_relocation, sonoma:        "ad4fd6304e08711ed565dcbf575161b614f1e127999d8011fb731d369ea9ab60"
    sha256 cellar: :any_skip_relocation, arm64_linux:   "ad4fd6304e08711ed565dcbf575161b614f1e127999d8011fb731d369ea9ab60"
    sha256 cellar: :any_skip_relocation, x86_64_linux:  "ad4fd6304e08711ed565dcbf575161b614f1e127999d8011fb731d369ea9ab60"
  end

  depends_on "python@3.14"

  resource "build" do
    url "https://files.pythonhosted.org/packages/25/1c/23e33405a7c9eac261dff640926b8b5adaed6a6eb3e1767d441ed611d0c0/build-1.3.0.tar.gz"
    sha256 "698edd0ea270bde950f53aed21f3a0135672206f3911e0176261a31e0e07b397"
  end

  resource "click" do
    url "https://files.pythonhosted.org/packages/46/61/de6cd827efad202d7057d93e0fed9294b96952e188f7384832791c7b2254/click-8.3.0.tar.gz"
    sha256 "e7b8232224eba16f4ebe410c25ced9f7875cb5f3263ffc93cc3e8da705e229c4"
  end

  resource "packaging" do
    url "https://files.pythonhosted.org/packages/a1/d4/1fc4078c65507b51b96ca8f8c3ba19e6a61c8253c72794544580a7b6c24d/packaging-25.0.tar.gz"
    sha256 "d443872c98d677bf60f6a1f2f8c1cb748e8fe762d2bf9d3148b5599295b0fc4f"
  end

  resource "pyproject-hooks" do
    url "https://files.pythonhosted.org/packages/e7/82/28175b2414effca1cdac8dc99f76d660e7a4fb0ceefa4b4ab8f5f6742925/pyproject_hooks-1.2.0.tar.gz"
    sha256 "1e859bd5c40fae9448642dd871adf459e5e2084186e8d2c2a79a824c970da1f8"
  end

  resource "setuptools" do
    url "https://files.pythonhosted.org/packages/18/5d/3bf57dcd21979b887f014ea83c24ae194cfcd12b9e0fda66b957c69d1fca/setuptools-80.9.0.tar.gz"
    sha256 "f36b47402ecde768dbfafc46e8e4207b4360c654f1f3bb84475f0a28628fb19c"
  end

  resource "wheel" do
    url "https://files.pythonhosted.org/packages/8a/98/2d9906746cdc6a6ef809ae6338005b3f21bb568bea3165cfc6a243fdc25c/wheel-0.45.1.tar.gz"
    sha256 "661e1abd9198507b1409a20c02106d9670b2576e916d58f520316666abca6729"
  end

  def install
    virtualenv_install_with_resources

    %w[pip-compile pip-sync].each do |script|
      generate_completions_from_executable(bin/script, shell_parameter_format: :click)
    end
  end

  test do
    (testpath/"requirements.in").write <<~REQUIREMENTS
      pip-tools
      typing-extensions
    REQUIREMENTS

    compiled = shell_output("#{bin}/pip-compile requirements.in -q -o -")
    assert_match "This file is autogenerated by pip-compile", compiled
    assert_match "# via pip-tools", compiled
  end
end
